﻿using System;
using System.Web;
using System.Web.Routing;

namespace BlueSky.Web.Routing
{
    public class IsGuidConstraint : IRouteConstraint
    {
        public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
        {
            if (values[parameterName] != null)
            {
                string sValue = values[parameterName].ToString();
                if (!string.IsNullOrEmpty(sValue))
                {
                    Guid gValue;
                    try
                    {
                        gValue = new Guid(sValue);
                        return true;
                    }
                    catch
                    {
                    }
                }
            }
            return false;
        }
    }
}
